home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nibble Magazine
/
nib12.dsk
/
SORT DEMO PROGRAM 1.bas
< prev
next >
Wrap
BASIC Source File
|
2023-02-26
|
2KB
|
46 lines
0 HOME : GOTO 110
10 Z = 1
20 Z = 3 *Z +1: IF Z <NUM THEN 20
30 Z = (Z -1)/3: IF Z <1 THEN RETURN
40 FOR I = Z +L TO H:J = I -Z
50 K = J +Z: IF A = ( MID$ (NA$(J),M,N) > MID$ (NA$(K),M,N)) THEN TEMP$ = NA$(J):NA$(J) = NA$(K):NA$(K) = TEMP$:J = J -Z: IF J > = L THEN 50
60 NEXT I: GOTO 30
110 :
120 :
130 REM FIX RANDOM NUMBER GENERATOR
140 :
150 :
160 POKE 201,128: POKE 202,79: POKE 203,199: POKE 204,82: POKE 205,255
180 DIM NA$(500),B$(500)
190 :
200 :
210 REM GENERATE RANDOM WORDS TO SORT
220 :
230 :
240 HOME : VTAB 12: HTAB 12: INPUT "HOW MANY WORDS? ";X$:NUM = VAL(X$): IF NUM <1 OR NUM >500 THEN PRINT CHR$(7): GOTO 240
250 VTAB 12: HTAB 7: FLASH : PRINT "GENERATING "NUM" RANDOM WORDS": NORMAL
260 FOR I = 1 TO NUM:A$ = "": FOR J = 1 TO 10:A$ = A$ + CHR$( INT( RND(1) *26 +65)): NEXT :NA$(I) = A$:B$(I) = A$: NEXT
270 :
280 :
290 REM IF YOU WISH TO TIME THE SORT
300 REM START THE TIMER AS SOON AS THE
310 REM WORD SORTING STARTS TO FLASH
320 :
330 :
340 HOME : VTAB 12: HTAB 6: PRINT "PRESS ANY KEY TO BEGIN SORT"
350 X = PEEK( -16384): IF X <128 THEN 350
360 POKE -16368,0
370 :
380 :
390 REM SORT INTO ASCENDING ORDER
400 :
410 :
420 HOME :L = 1:H = NUM:M = 1:N = 10:A = 1:X = FRE(0): VTAB 12: HTAB 17: FLASH : PRINT "SORTING" CHR$(7): NORMAL : GOSUB 10: PRINT CHR$(7)
430 :
440 :
450 REM PRINT OUT SORTED AND UNSORTED WORDS
460 :
470 :
480 HOME : HTAB 10: INVERSE : PRINT NUM" RANDOM WORDS": PRINT : HTAB 8: PRINT "UNSORTED";: HTAB 22: PRINT "SORTED": NORMAL : POKE 34,4
490 HOME : FOR I = 1 TO NUM: PRINT RIGHT$(" " + STR$(I),4)". "B$(I);: HTAB 20: PRINT NA$(I): NEXT
500 PRINT : HTAB 12: PRINT "ALL DONE ...": FOR I = 1 TO 5000: NEXT : TEXT : CLEAR : GOTO 180